<?php

  require_once "JooS/Server/Resource/DataElement.php";
  require_once "JooS/Server/Resource/DataText.php";

  class JooS_Server_Resource_DataElement_List extends ArrayObject {
    public function __construct() {
      parent::__construct(array());
    }

    public function offsetGet($offset) {
      return parent::offsetGet($offset);
    }

    public function offsetSet($offset, $value) {
      switch (true) {
        case ($value instanceof JooS_Server_Resource_DataText || $value instanceof JooS_Server_Resource_DataElement):
          $objValue = $value;
          break;
        default:
          $dValue = "";
          switch (true) {
            case is_scalar($value):
              $dValue = (string)$value;
              break;
            case is_object($value):
            case is_array($value):
              $dValue = $value;
              break;
            default:
              break;
          }

          if (is_scalar($dValue))
            $objValue = new JooS_Server_Resource_DataText($offset, $dValue);
          else {
            $objValue = new JooS_Server_Resource_DataElement($offset);
            foreach ($dValue as $k => $v) {
              $objValue->__set((string)$k, $v);
            }
          }
          break;
      }

      parent::offsetSet($offset, $objValue);
    }
  }

?>